/*
 * Copyright (C) 2010  Pace Plc
 * All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * - Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * - Neither the name of Sun Microsystems, Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/* FIXME: this needs to be auto generated by the configure script.
 * It should gurantee the following when included:
 * uint32_t/ etc get defined.
 * ntoh32/hton32 get defined.
 */


#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <errno.h>
#include <stdint.h>
#include <stdbool.h>

#include "config.h"

#ifndef ntoh32
#define ntoh32(_val)  ntohl(_val)
#endif
#ifndef hton32
#define hton32(_val)  htonl(_val)
#endif

#ifndef HAVE_STRLCAT
size_t   strlcat(char *, const char *, size_t);
#endif
#ifndef HAVE_STRLCPY
size_t   strlcpy(char *, const char *, size_t);
#endif

#ifndef HAVE_STRNLEN
size_t  strnlen(const char *s, size_t maxlen);
#endif

#if defined(HAVE_DECL_CLOCKID_T) && !HAVE_DECL_CLOCKID_T
typedef int clockid_t;
#endif
#if defined(HAVE_DECL_CLOCK_GETTIME) && !HAVE_DECL_CLOCK_GETTIME
struct timespec;
extern int clock_gettime(clockid_t clock_id, struct timespec *tp);
#endif

#ifndef HAVE_STRUCT_UCRED
struct ucred {
	int pid;
	int uid;
	int gid;
};
#endif

#if defined(LOCAL_PEERCRED) && !defined(SO_PEERCRED)
#define SO_PEERCRED LOCAL_PEERCRED
#endif

/* FIXME: generate from autoconf */
#define RPC_UINT64_FMT  "%lu"
#define RPC_INT64_FMT   "%ld"
#define RPC_UINT32_FMT  "%u"
#define RPC_INT32_FMT   "%d"
#define RPC_UINT16_FMT  "%hu"
#define RPC_INT16_FMT   "%hd"
#define RPC_ENUM_FMT    "%d"

#ifndef EPARSE
#define EPARSE EBADMSG
#endif

#define ar_offsetof(_type, _field) ((unsigned int)&(((_type *)0)->_field))

#ifndef __FBSDID
#define __FBSDID(_str)
#endif
